(function(){"use strict";BX.namespace("BX.Landing.UI.Panel");var t=BX.Landing.Utils.addClass;var i=BX.Landing.Utils.create;var n=BX.Landing.Utils.append;var e=BX.Landing.Utils.debounce;var a=BX.Landing.Utils.trim;var s=BX.Landing.Utils.bind;var l=BX.Landing.Utils.proxy;var o=BX.Landing.Utils.setTextContent;var r=BX.Landing.Utils.htmlToElement;var c=BX.Landing.Utils.remove;var h=BX.Landing.Utils.style;var d=BX.Landing.Utils.isArray;var g=BX.Landing.Utils.prepend;var u=BX.Landing.Utils.data;var L=BX.Landing.Utils.encodeDataValue;var p="section";var C="element";var y="all";BX.Landing.UI.Panel.Catalog=function(i){BX.Landing.UI.Panel.Content.apply(this,arguments);this.searchContainer=this.createSearchContainer();this.listContainer=this.createListContainer();this.searchField=this.createSearchField();this.typeSwitcher=this.createTypeSwitcher();this.iBlockSwitcher=this.createIblockSwitcher();this.resolver=function(){};this.iblocks=null;t(this.layout,"landing-ui-panel-catalog");t(this.overlay,"landing-ui-panel-catalog");o(this.title,BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_TITLE"));if(!this.getIblocks()||this.getIblocks().length>1){n(this.iBlockSwitcher.layout,this.searchContainer)}else{void h(this.listContainer,{"margin-top":"94px"})}n(this.searchField.layout,this.searchContainer);n(this.typeSwitcher.layout,this.searchContainer);n(this.searchContainer,this.content);n(this.listContainer,this.content);if(BX.Landing.Main.isExternalControlsEnabled()){n(this.layout,parent.document.body)}else{n(this.layout,document.body);this.layout.style.marginTop=0;this.overlay.style.display="none"}};BX.Landing.UI.Panel.Catalog.TYPE_CATALOG_ALL=y;BX.Landing.UI.Panel.Catalog.TYPE_CATALOG_SECTION=p;BX.Landing.UI.Panel.Catalog.TYPE_CATALOG_ELEMENT=C;BX.Landing.UI.Panel.Catalog.getInstance=function(){return BX.Landing.UI.Panel.Catalog.instance||(BX.Landing.UI.Panel.Catalog.instance=new BX.Landing.UI.Panel.Catalog("catalog_panel"))};BX.Landing.UI.Panel.Catalog.prototype={constructor:BX.Landing.UI.Panel.Catalog,__proto__:BX.Landing.UI.Panel.Content.prototype,superClass:BX.Landing.UI.Panel.Content.prototype,search:function(t){var i={query:a(t.replace("&nbsp;","")),type:this.typeSwitcher.getValue(),iblock:this.iBlockSwitcher.getValue()};var n={action:"Utils::catalogSearch"};return BX.Landing.Backend.getInstance().action("Utils::catalogSearch",i,n)},createTypeSwitcher:function(){var i=new BX.Landing.UI.Field.ButtonGroup({items:[{name:BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_SEARCH_TYPE_ALL"),value:y},{name:BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_SEARCH_TYPE_ELEMENTS"),value:C},{name:BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_SEARCH_TYPE_SECTIONS"),value:p}],content:y,onChange:this.onSearchTypeChange.bind(this)});t(i.layout,"landing-ui-panel-catalog-switch");return i},getIblocks:function(){if(d(this.iblocks)){return this.iblocks}return[{name:"",value:""}]},createIblockSwitcher:function(){var i=new BX.Landing.UI.Field.Dropdown({title:BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_IBLOCK_SWITCHER"),items:this.getIblocks(),content:d(this.getIblocks())?this.getIblocks()[0].value:"",onChange:this.onIblockChange.bind(this)});t(i.layout,"landing-ui-panel-catalog-iblock-switch");return i},onIblockChange:function(){this.onSearch()},createSearchField:function(){return new BX.Landing.UI.Field.Text({placeholder:BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_SEARCH_PLACEHOLDER"),textOnly:true,onValueChange:e(this.onSearch,200,this)})},createSearchContainer:function(){return i("div",{props:{className:"landing-ui-panel-catalog-search-container"}})},createListContainer:function(){return i("div",{props:{className:"landing-ui-panel-catalog-list-container"}})},onSearchTypeChange:function(){this.onSearch()},renderResponse:function(t){var i=this.listContainer.querySelector(".landing-ui-panel-catalog-list");if(i){c(i)}this.body.scrollTop=0;n(r('<div class="landing-ui-panel-catalog-list">'+t.map((function(t){if(t.subType===p&&!t.image){t.image="/bitrix/images/landing/folder.svg"}var i=t.chain.reduce((function(t,i){if(i){t.push(L(i))}return t}),[]);return"<div class='landing-ui-panel-catalog-list-row landing-ui-panel-catalog-list-row-"+t.subType+"'>"+"<div class='landing-ui-panel-catalog-list-row-left'>"+"<div class='landing-ui-panel-catalog-list-cell-preview' style=\"background-image: url('"+t.image+"')\"></div>"+"</div>"+"<div class='landing-ui-panel-catalog-list-row-right'>"+"<div class='landing-ui-panel-catalog-list-cell-name'>"+"<div>"+L(t.name)+"</div>"+"</div>"+"<div class='landing-ui-panel-catalog-list-cell-chain'>"+"<div>"+(i?i.join("&nbsp;/&nbsp;"):"")+"</div>"+"</div>"+"</div>"+"</div>"})).join("")+"</div>"),this.listContainer);return t},initResponseItems:function(t){var i=this.listContainer.querySelector(".landing-ui-panel-catalog-list");t.forEach((function(t,n){s(i.children[n],"click",this.onItemClick.bind(this,t))}),this);return t},show:function(t,i){this.superClass.show.call(this);this.iblocks=t||null;this.entityTypes=i;this.onSearch();this.adjustIblockSwitcher();this.adjustEntityTypes();this.adjustSearchPlaceholder();return new Promise(function(t){this.resolver=t}.bind(this))},adjustSearchPlaceholder:function(){var t=this.getEntityTypes();if(t.length===1&&t[0]===p){u(this.searchField.input,{"data-placeholder":BX.Landing.Loc.getMessage("LANDING_STYLE_PANEL_CATALOG_SEARCH_SECTION_PLACEHOLDER")})}},getEntityTypes:function(){if(d(this.entityTypes)&&this.entityTypes.length>0){return this.entityTypes}return[y,C,p]},adjustEntityTypes:function(){this.typeSwitcher.buttons.forEach((function(t){t.layout.hidden=!this.getEntityTypes().includes(t.id)}),this);this.typeSwitcher.setValue(this.getEntityTypes()[0])},adjustIblockSwitcher:function(){c(this.iBlockSwitcher.layout);this.iBlockSwitcher=this.createIblockSwitcher();g(this.iBlockSwitcher.layout,this.searchContainer);if(!this.getIblocks()||this.getIblocks().length<2){void h(this.iBlockSwitcher.layout,{display:"none"});void h(this.loaderContainer,{top:"182px"});void h(this.listContainer,{"margin-top":"94px"})}else{void h(this.iBlockSwitcher.layout,{display:null});void h(this.loaderContainer,{top:null});void h(this.listContainer,{"margin-top":null})}},onSearch:function(){this.showLoader();clearTimeout(this.searchTimeout);this.searchTimeout=setTimeout(function(){this.search(this.searchField.getValue()).then(l(this.renderResponse,this)).then(l(this.initResponseItems,this)).then(function(){this.hideLoader()}.bind(this))}.bind(this),500)},showLoader:function(){if(!this.loader){this.loader=new BX.Loader({offset:{top:"-70px"}});this.loaderContainer=i("div",{props:{className:"landing-ui-panel-catalog-loader-container"},children:[this.loader.layout]});n(this.loaderContainer,this.listContainer);this.loader.show()}this.loaderContainer.hidden=false},hideLoader:function(){if(this.loaderContainer){this.loaderContainer.hidden=true}},onItemClick:function(t){this.resolver(t);this.hide()}}})();
//# sourceMappingURL=catalog_panel.map.js